import instacne from "../request";
import type { Ref } from "vue";

// 获取所有的商品列表数据
interface prefrenceArea {
  total: number;
  list: any;
  id: number;
  name: string;
  pic: string;
  showStatus: number;
  sort: number;
  subTitle: string;
}

interface prefrenceAreaData {
  brandId?: number;
  keyword: string;
  pageNum?: number;
  pageSize?: number;
  productCategoryId?: number;
  productSn?: string;
  publishStatus?: string;
  verifyStatus?: string;
}
// 查询商品 /product/list
// 参数接口
interface ProductList {
  brandId?: number;
  keyword?: string;
  productCategoryId?: number;
  productSn?: string;
  publishStatus?: string;
  verifyStatus?: string;
  pageNum?: number;
  pageSize?: number;
}
// 所有商品列表数据
const prefrenceArealistAll = (data: ProductList): Promise<prefrenceArea> => {
  return instacne.get("/product/list", { params: data });
};

// 更新上架信息  /product/update/publishStatus
interface UpdatepublishStatus {
  ids: number;
  publishStatus: number;
}

const publishStatus = (data: UpdatepublishStatus): Promise<prefrenceArea> => {
  return instacne.post(
    `/product/update/publishStatus?ids=${data.ids}&publishStatus=${data.publishStatus}`
  );
};

// 更新新品信息 /product/update/newStatus
interface UpdateNewStatus {
  ids: number;
  newStatus: number;
}

const productUpdateNewStatus = (
  data: UpdateNewStatus
): Promise<prefrenceArea> => {
  return instacne.post(
    `/product/update/newStatus?ids=${data.ids}&newStatus=${data.newStatus}`
  );
};

// 推荐商品 /product/update/recommendStatus
interface RecommendStatus {
  ids: number;
  recommendStatus: number;
}

const productUpdateRecommendStatus = (
  data: RecommendStatus
): Promise<prefrenceArea> => {
  return instacne.post(
    `/product/update/recommendStatus?ids=${data.ids}&recommendStatus=${data.recommendStatus}`
  );
};

// 删除数据 /product/update/deleteStatus
interface DeleteStatusData {
  deleteStatus: number;
  ids: number;
}

const productUpdateDeleteStatus = (
  data: DeleteStatusData
): Promise<prefrenceArea> => {
  return instacne.post(
    `/product/update/deleteStatus?ids=${data.ids}&deleteStatus=${data.deleteStatus}`
  );
};

// 商品分类请求 /brand/list
interface BrandList {
  pageNum: number;
  pageSize: number;
}
interface ProDataList {
  value: string;
  label: string;
  name: string;
}
interface ProData {
  list: ProDataList[];
}

const brandListApi = (data: BrandList): Promise<ProData> => {
  return instacne.get(
    `/brand/list?pageNum=${data.pageNum}&pageSize=${data.pageSize}`
  );
};

export {
  prefrenceArealistAll,
  publishStatus,
  productUpdateNewStatus,
  productUpdateRecommendStatus,
  productUpdateDeleteStatus,
  brandListApi,
};
export type { prefrenceAreaData, UpdatepublishStatus, UpdateNewStatus };
